<script setup name="LoginLog">

import {getLoginLogPageList} from "@/api/system/loginLog.js";

const {proxy} = getCurrentInstance()
const loginLogList = ref([])
const loading = ref(true)
const showSearch = ref(true)
const total = ref(0)
const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    dateRange: [],
    nickName: undefined
  }
})
const {queryParams} = toRefs(data)

onMounted(() => {
  getList()
})

/** 查询列表 */
function getList() {
  loading.value = true
  getLoginLogPageList(proxy.addDateRange(queryParams.value)).then(result => {
    loginLogList.value = result.list
    total.value = result.total
    loading.value = false
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  queryParams.value.dateRange = []
  handleQuery()
}

</script>

<template>
  <div class="app-container">
    <el-form @submit.native.prevent :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="68px">
      <el-form-item label="真实姓名" prop="nickName">
        <el-input
            v-model="queryParams.nickName"
            placeholder="请输入用户真实姓名"
            clearable
            style="width: 240px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="登录时间" style="width: 308px;">
        <el-date-picker
            v-model="queryParams.dateRange"
            value-format="YYYY-MM-DD"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 表格数据 -->
    <el-table v-loading="loading" :data="loginLogList">
      <el-table-column label="真实姓名" prop="nickName" :show-overflow-tooltip="true" width="200"/>
      <el-table-column label="登录IP" prop="ip" width="300"/>
      <el-table-column label="登录时间" prop="loginTime" />
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>
